<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python基础语言 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>列表的常见操作 | python基础语言</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../05day/section.8.html" />
    
    
    <link rel="prev" href="../05day/section.6.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="3.8"
        data-chapter-title="列表的常见操作"
        data-filepath="05day/section.7.md"
        data-basepath=".."
        data-revision="Thu Apr 06 2017 08:01:50 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="03day/index.html">
            
                
                    <a href="../03day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        认识python和基础知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="03day/section.1.html">
            
                
                    <a href="../03day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        认识python(了解)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="03day/section.2.html">
            
                
                    <a href="../03day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        第一个python程序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="03day/section.3.html">
            
                
                    <a href="../03day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        注释
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="03day/section.4.html">
            
                
                    <a href="../03day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        变量以及类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="03day/section.5.html">
            
                
                    <a href="../03day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        标示符和关键字
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="03day/section.6.html">
            
                
                    <a href="../03day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        输出
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="03day/section.4.1.html">
            
                
                    <a href="../03day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        输入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="03day/section.7.html">
            
                
                    <a href="../03day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="03day/section.10.html">
            
                
                    <a href="../03day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.9.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="04day/section.1.html">
            
                
                    <a href="../04day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.10.</b>
                        
                        判断语句介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="04day/section.2.html">
            
                
                    <a href="../04day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.11.</b>
                        
                        if语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="04day/section.3.html">
            
                
                    <a href="../04day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.12.</b>
                        
                        比较、关系运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="03day/section.99.html">
            
                
                    <a href="../03day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.13.</b>
                        
                        作业
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="03day/section.8.html">
            
                
                    <a href="../03day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.14.</b>
                        
                        附录-推荐的python电子书
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="04day/index.html">
            
                
                    <a href="../04day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        判断语句和循环语句
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="04day/section.4.html">
            
                
                    <a href="../04day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        if-else
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="04day/section.4.1.html">
            
                
                    <a href="../04day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        elif
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="04day/section.5.html">
            
                
                    <a href="../04day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        if嵌套
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="04day/section.6.html">
            
                
                    <a href="../04day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        if应用:猜拳游戏
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="04day/section.7.html">
            
                
                    <a href="../04day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        循环语句介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="04day/section.8.html">
            
                
                    <a href="../04day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        while循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="04day/section.8.1.html">
            
                
                    <a href="../04day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        while循环应用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="04day/section.9.html">
            
                
                    <a href="../04day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        while循环的嵌套以及应用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="04day/section.11.html">
            
                
                    <a href="../04day/section.11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        for循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="04day/section.10.html">
            
                
                    <a href="../04day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        break和continue
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="04day/section.12.html">
            
                
                    <a href="../04day/section.12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        总结
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="04day/section.99.html">
            
                
                    <a href="../04day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="05day/index.html">
            
                
                    <a href="../05day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        字符串、列表、元组、字典
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="05day/section.1.html">
            
                
                    <a href="../05day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        字符串介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="05day/section.2.html">
            
                
                    <a href="../05day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        字符串输出
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="05day/section.3.html">
            
                
                    <a href="../05day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        字符串输入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="05day/section.4.html">
            
                
                    <a href="../05day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        下标和切片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="05day/section.4.2.html">
            
                
                    <a href="../05day/section.4.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        字符串常见操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="05day/section.5.html">
            
                
                    <a href="../05day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        列表介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="05day/section.6.html">
            
                
                    <a href="../05day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        列表的循环遍历
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.8" data-path="05day/section.7.html">
            
                
                    <a href="../05day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        列表的常见操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="05day/section.8.html">
            
                
                    <a href="../05day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        列表的嵌套
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="06day/section.3.html">
            
                
                    <a href="../06day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="06day/section.1.html">
            
                
                    <a href="../06day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        字典介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="06day/section.2.html">
            
                
                    <a href="../06day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        字典的常见操作1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="06day/section.2.1.html">
            
                
                    <a href="../06day/section.2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        字典的常见操作2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="06day/section.2.2.html">
            
                
                    <a href="../06day/section.2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        字典的遍历
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.15" data-path="06day/section.2.3.html">
            
                
                    <a href="../06day/section.2.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.15.</b>
                        
                        公共方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.16" data-path="05day/section.99.html">
            
                
                    <a href="../05day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.16.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="06day/index.html">
            
                
                    <a href="../06day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        函数
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="07day/section.1.html">
            
                
                    <a href="../07day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        函数介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="07day/section.2.html">
            
                
                    <a href="../07day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        函数定义、调用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="07day/section.2.1.html">
            
                
                    <a href="../07day/section.2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        函数的文档说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="07day/section.3.html">
            
                
                    <a href="../07day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        函数参数(一)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="07day/section.4.html">
            
                
                    <a href="../07day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        函数返回值(一)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="07day/section.5.html">
            
                
                    <a href="../07day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        4种函数的类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="07day/section.6.html">
            
                
                    <a href="../07day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        函数的嵌套调用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="07day/section.6.1.html">
            
                
                    <a href="../07day/section.6.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        函数应用：打印图形和数学计算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="07day/section.7.0.html">
            
                
                    <a href="../07day/section.7.0.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        局部变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="07day/section.8.html">
            
                
                    <a href="../07day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        全局变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="07day/section.8.1.html">
            
                
                    <a href="../07day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        函数应用：学生管理系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="06day/section.4.1.html">
            
                
                    <a href="../06day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.12.</b>
                        
                        函数返回值(二)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="06day/section.3.1.html">
            
                
                    <a href="../06day/section.3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.13.</b>
                        
                        函数参数(二)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="06day/section.2.4.html">
            
                
                    <a href="../06day/section.2.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.14.</b>
                        
                        引用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.15" data-path="07day/section.9.html">
            
                
                    <a href="../07day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.15.</b>
                        
                        递归函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.16" data-path="07day/section.9.1.html">
            
                
                    <a href="../07day/section.9.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.16.</b>
                        
                        匿名函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.17" data-path="07day/section.7.html">
            
                
                    <a href="../07day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.17.</b>
                        
                        函数使用注意事项
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.18" data-path="07day/section.99.html">
            
                
                    <a href="../07day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.18.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="08day/index.html">
            
                
                    <a href="../08day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        文件操作、综合应用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="08day/section.1.html">
            
                
                    <a href="../08day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        文件操作介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="08day/section.2.html">
            
                
                    <a href="../08day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        文件的打开与关闭
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="08day/section.3.html">
            
                
                    <a href="../08day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        文件的读写
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="08day/section.3.1.html">
            
                
                    <a href="../08day/section.3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        应用1:制作文件的备份
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="08day/section.4.html">
            
                
                    <a href="../08day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        文件的定位读写
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="08day/section.5.html">
            
                
                    <a href="../08day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件的重命名、删除
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="08day/section.6.html">
            
                
                    <a href="../08day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        文件夹的相关操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="08day/section.9.html">
            
                
                    <a href="../08day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        应用2:批量修改文件名
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="08day/section.10.html">
            
                
                    <a href="../08day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        综合应用:学生管理系统(文件版)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="08day/section.99.html">
            
                
                    <a href="../08day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="09day/index.html">
            
                
                    <a href="../09day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        面向对象1
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="09day/section.1.html">
            
                
                    <a href="../09day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        面向对象编程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="09day/section.2.html">
            
                
                    <a href="../09day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        类和对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="09day/section.3.html">
            
                
                    <a href="../09day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        定义类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="09day/section.4.html">
            
                
                    <a href="../09day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        创建对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="09day/section.5.html">
            
                
                    <a href="../09day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        __init__方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="09day/section.5.1.html">
            
                
                    <a href="../09day/section.5.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        应用:创建多个对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="09day/section.4.4.html">
            
                
                    <a href="../09day/section.4.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        &quot;魔法&quot;方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="09day/section.4.1.html">
            
                
                    <a href="../09day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        self
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.9" data-path="09day/section.5.2.html">
            
                
                    <a href="../09day/section.5.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.9.</b>
                        
                        应用:烤地瓜
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.10" data-path="09day/section.5.4.html">
            
                
                    <a href="../09day/section.5.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.10.</b>
                        
                        隐藏数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.11" data-path="09day/section.5.3.html">
            
                
                    <a href="../09day/section.5.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.11.</b>
                        
                        应用:存放家具
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="10day/index.html">
            
                
                    <a href="../10day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        面向对象2
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="09day/section.12.html">
            
                
                    <a href="../09day/section.12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        应用:老王开枪
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="09day/section.4.3.html">
            
                
                    <a href="../09day/section.4.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        保护对象的属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="09day/section.6.html">
            
                
                    <a href="../09day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        __del__方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="09day/section.7.html">
            
                
                    <a href="../09day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        单继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="09day/section.8.html">
            
                
                    <a href="../09day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        多继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="09day/section.8.1.html">
            
                
                    <a href="../09day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        重写父类方法与调用父类方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="09day/section.9.html">
            
                
                    <a href="../09day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        多态
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.8" data-path="09day/section.9.1.html">
            
                
                    <a href="../09day/section.9.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.8.</b>
                        
                        类属性、实例属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.9" data-path="09day/section.10.html">
            
                
                    <a href="../09day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.9.</b>
                        
                        静态方法和类方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="11day/index.html">
            
                
                    <a href="../11day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        面向对象3、异常、模块
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="09day/section.15.html">
            
                
                    <a href="../09day/section.15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        练习：设计类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="09day/section.14.html">
            
                
                    <a href="../09day/section.14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        工厂模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="11day/section.4.html">
            
                
                    <a href="../11day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        __new__方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="09day/section.13.html">
            
                
                    <a href="../09day/section.13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        单例模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="10day/section.1.html">
            
                
                    <a href="../10day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        异常介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="10day/section.2.html">
            
                
                    <a href="../10day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        捕获异常
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="10day/section.2.2.html">
            
                
                    <a href="../10day/section.2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        异常的传递
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.8" data-path="10day/section.3.html">
            
                
                    <a href="../10day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.8.</b>
                        
                        抛出自定义的异常
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.9" data-path="10day/section.3.2.html">
            
                
                    <a href="../10day/section.3.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.9.</b>
                        
                        异常处理中抛出异常
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.10" data-path="08day/section.7.html">
            
                
                    <a href="../08day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.10.</b>
                        
                        模块介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.11" data-path="08day/section.8.html">
            
                
                    <a href="../08day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.11.</b>
                        
                        模块制作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.12" data-path="08day/section.8.3.html">
            
                
                    <a href="../08day/section.8.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.12.</b>
                        
                        模块中的__all__
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.13" data-path="08day/section.7.1.html">
            
                
                    <a href="../08day/section.7.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.13.</b>
                        
                        python中的包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.14" data-path="08day/section.8.1.html">
            
                
                    <a href="../08day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.14.</b>
                        
                        模块发布
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.15" data-path="08day/section.8.2.html">
            
                
                    <a href="../08day/section.8.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.15.</b>
                        
                        模块安装、使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="12day/index.html">
            
                
                    <a href="../12day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        强化练习
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="12day/section.3.html">
            
                
                    <a href="../12day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        给程序传参数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="12day/section.4.html">
            
                
                    <a href="../12day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        列表推导式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="12day/section.5.html">
            
                
                    <a href="../12day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        set、list、tuple
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="12day/section.2.html">
            
                
                    <a href="../12day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.4.</b>
                        
                        面试题1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.5" data-path="12day/section.1.html">
            
                
                    <a href="../12day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.5.</b>
                        
                        面试题2
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="07day/index.html">
            
                
                    <a href="../07day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        应用:打飞机
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="10day/section.5.html">
            
                
                    <a href="../10day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        打飞机代码：搭建界面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="10day/section.6.html">
            
                
                    <a href="../10day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        打飞机代码：检测键盘
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="10day/section.7.html">
            
                
                    <a href="../10day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                        打飞机代码：显示、控制玩具飞机-面向过程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="10day/section.8.html">
            
                
                    <a href="../10day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.4.</b>
                        
                        打飞机代码：显示、控制玩具飞机-面向对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="10day/section.9.html">
            
                
                    <a href="../10day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.5.</b>
                        
                        打飞机代码：玩家飞机发射子弹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="10day/section.12.html">
            
                
                    <a href="../10day/section.12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.6.</b>
                        
                        打飞机代码：显示敌机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.7" data-path="10day/section.11.html">
            
                
                    <a href="../10day/section.11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.7.</b>
                        
                        打飞机代码：优化代码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.8" data-path="10day/section.13.html">
            
                
                    <a href="../10day/section.13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.8.</b>
                        
                        打飞机代码：让敌机移动
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.9" data-path="10day/section.14.html">
            
                
                    <a href="../10day/section.14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.9.</b>
                        
                        打飞机代码：敌机发射子弹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.10" data-path="10day/section.16.html">
            
                
                    <a href="../10day/section.16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.10.</b>
                        
                        打飞机代码：代码优化-抽象出基类
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python基础语言</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5217;&#x8868;&#x7684;&#x76F8;&#x5173;&#x64CD;&#x4F5C;">&#x5217;&#x8868;&#x7684;&#x76F8;&#x5173;&#x64CD;&#x4F5C;</h1>
<p>&#x5217;&#x8868;&#x4E2D;&#x5B58;&#x653E;&#x7684;&#x6570;&#x636E;&#x662F;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x7684;&#xFF0C;&#x6BD4;&#x5982;&quot;&#x589E;&quot;&#x3001;&quot;&#x5220;&quot;&#x3001;&quot;&#x6539;&quot;&quot;</p>
<h2 id="&#x6DFB;&#x52A0;&#x5143;&#x7D20;&#x589E;append-extend-insert"><1>&#x6DFB;&#x52A0;&#x5143;&#x7D20;(&quot;&#x589E;&quot;append, extend, insert)</1></h2>
<h4 id="append">append</h4>
<p>&#x901A;&#x8FC7;append&#x53EF;&#x4EE5;&#x5411;&#x5217;&#x8868;&#x6DFB;&#x52A0;&#x5143;&#x7D20;</p>
<p>demo:</p>
<pre><code class="lang-python">    <span class="hljs-comment">#&#x5B9A;&#x4E49;&#x53D8;&#x91CF;A&#xFF0C;&#x9ED8;&#x8BA4;&#x6709;3&#x4E2A;&#x5143;&#x7D20;</span>
    A = [<span class="hljs-string">&apos;xiaoWang&apos;</span>,<span class="hljs-string">&apos;xiaoZhang&apos;</span>,<span class="hljs-string">&apos;xiaoHua&apos;</span>]

    print(<span class="hljs-string">&quot;-----&#x6DFB;&#x52A0;&#x4E4B;&#x524D;&#xFF0C;&#x5217;&#x8868;A&#x7684;&#x6570;&#x636E;-----&quot;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> A:
        print(tempName)

    <span class="hljs-comment">#&#x63D0;&#x793A;&#x3001;&#x5E76;&#x6DFB;&#x52A0;&#x5143;&#x7D20;</span>
    temp = input(<span class="hljs-string">&apos;&#x8BF7;&#x8F93;&#x5165;&#x8981;&#x6DFB;&#x52A0;&#x7684;&#x5B66;&#x751F;&#x59D3;&#x540D;:&apos;</span>)
    A.append(temp)

    print(<span class="hljs-string">&quot;-----&#x6DFB;&#x52A0;&#x4E4B;&#x540E;&#xFF0C;&#x5217;&#x8868;A&#x7684;&#x6570;&#x636E;-----&quot;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> A:
        print(tempName)
</code></pre>
<p>&#x7ED3;&#x679C;:</p>
<p><img src="../Images/01-&#x7B2C;3&#x5929;-2.gif" alt="&#x7ED3;&#x679C;"></p>
<h4 id="extend">extend</h4>
<p>&#x901A;&#x8FC7;extend&#x53EF;&#x4EE5;&#x5C06;&#x53E6;&#x4E00;&#x4E2A;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x9010;&#x4E00;&#x6DFB;&#x52A0;&#x5230;&#x5217;&#x8868;&#x4E2D;</p>
<pre><code class="lang-python"><span class="hljs-prompt">&gt;&gt;&gt; </span>a = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>b = [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.append(b)
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.extend(b)
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>], <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
</code></pre>
<h4 id="insert">insert</h4>
<p>insert(index, object) &#x5728;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;index&#x524D;&#x63D2;&#x5165;&#x5143;&#x7D20;object</p>
<pre><code class="lang-python"><span class="hljs-prompt">&gt;&gt;&gt; </span>a = [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.insert(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>)
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">0</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]
</code></pre>
<h2 id="&#x4FEE;&#x6539;&#x5143;&#x7D20;&#x6539;"><2>&#x4FEE;&#x6539;&#x5143;&#x7D20;(&quot;&#x6539;&quot;)</2></h2>
<p>&#x4FEE;&#x6539;&#x5143;&#x7D20;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8981;&#x901A;&#x8FC7;&#x4E0B;&#x6807;&#x6765;&#x786E;&#x5B9A;&#x8981;&#x4FEE;&#x6539;&#x7684;&#x662F;&#x54EA;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x7136;&#x540E;&#x624D;&#x80FD;&#x8FDB;&#x884C;&#x4FEE;&#x6539;</p>
<p>demo:</p>
<pre><code class="lang-python">    <span class="hljs-comment">#&#x5B9A;&#x4E49;&#x53D8;&#x91CF;A&#xFF0C;&#x9ED8;&#x8BA4;&#x6709;3&#x4E2A;&#x5143;&#x7D20;</span>
    A = [<span class="hljs-string">&apos;xiaoWang&apos;</span>,<span class="hljs-string">&apos;xiaoZhang&apos;</span>,<span class="hljs-string">&apos;xiaoHua&apos;</span>]

    print(<span class="hljs-string">&quot;-----&#x4FEE;&#x6539;&#x4E4B;&#x524D;&#xFF0C;&#x5217;&#x8868;A&#x7684;&#x6570;&#x636E;-----&quot;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> A:
        print(tempName)

    <span class="hljs-comment">#&#x4FEE;&#x6539;&#x5143;&#x7D20;</span>
    A[<span class="hljs-number">1</span>] = <span class="hljs-string">&apos;xiaoLu&apos;</span>

    print(<span class="hljs-string">&quot;-----&#x4FEE;&#x6539;&#x4E4B;&#x540E;&#xFF0C;&#x5217;&#x8868;A&#x7684;&#x6570;&#x636E;-----&quot;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> A:
        print(tempName)
</code></pre>
<p>&#x7ED3;&#x679C;:</p>
<pre><code>    -----&#x4FEE;&#x6539;&#x4E4B;&#x524D;&#xFF0C;&#x5217;&#x8868;A&#x7684;&#x6570;&#x636E;-----
    xiaoWang
    xiaoZhang
    xiaoHua
    -----&#x4FEE;&#x6539;&#x4E4B;&#x540E;&#xFF0C;&#x5217;&#x8868;A&#x7684;&#x6570;&#x636E;-----
    xiaoWang
    xiaoLu
    xiaoHua
</code></pre><h2 id="&#x67E5;&#x627E;&#x5143;&#x7D20;&#x67E5;in-not-in-index-count"><3>&#x67E5;&#x627E;&#x5143;&#x7D20;(&quot;&#x67E5;&quot;in, not in, index, count)</3></h2>
<p>&#x6240;&#x8C13;&#x7684;&#x67E5;&#x627E;&#xFF0C;&#x5C31;&#x662F;&#x770B;&#x770B;&#x6307;&#x5B9A;&#x7684;&#x5143;&#x7D20;&#x662F;&#x5426;&#x5B58;&#x5728;</p>
<h4 id="in-not-in">in, not in</h4>
<p>python&#x4E2D;&#x67E5;&#x627E;&#x7684;&#x5E38;&#x7528;&#x65B9;&#x6CD5;&#x4E3A;&#xFF1A;</p>
<ul>
<li>in&#xFF08;&#x5B58;&#x5728;&#xFF09;,&#x5982;&#x679C;&#x5B58;&#x5728;&#x90A3;&#x4E48;&#x7ED3;&#x679C;&#x4E3A;true&#xFF0C;&#x5426;&#x5219;&#x4E3A;false</li>
<li>not in&#xFF08;&#x4E0D;&#x5B58;&#x5728;&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x90A3;&#x4E48;&#x7ED3;&#x679C;&#x4E3A;true&#xFF0C;&#x5426;&#x5219;false</li>
</ul>
<p>demo</p>
<pre><code class="lang-python">    <span class="hljs-comment">#&#x5F85;&#x67E5;&#x627E;&#x7684;&#x5217;&#x8868;</span>
    nameList = [<span class="hljs-string">&apos;xiaoWang&apos;</span>,<span class="hljs-string">&apos;xiaoZhang&apos;</span>,<span class="hljs-string">&apos;xiaoHua&apos;</span>]

    <span class="hljs-comment">#&#x83B7;&#x53D6;&#x7528;&#x6237;&#x8981;&#x67E5;&#x627E;&#x7684;&#x540D;&#x5B57;</span>
    findName = input(<span class="hljs-string">&apos;&#x8BF7;&#x8F93;&#x5165;&#x8981;&#x67E5;&#x627E;&#x7684;&#x59D3;&#x540D;:&apos;</span>)

    <span class="hljs-comment">#&#x67E5;&#x627E;&#x662F;&#x5426;&#x5B58;&#x5728;</span>
    <span class="hljs-keyword">if</span> findName <span class="hljs-keyword">in</span> nameList:
        print(<span class="hljs-string">&apos;&#x5728;&#x5B57;&#x5178;&#x4E2D;&#x627E;&#x5230;&#x4E86;&#x76F8;&#x540C;&#x7684;&#x540D;&#x5B57;&apos;</span>)
    <span class="hljs-keyword">else</span>:
        print(<span class="hljs-string">&apos;&#x6CA1;&#x6709;&#x627E;&#x5230;&apos;</span>)
</code></pre>
<p>&#x7ED3;&#x679C;1&#xFF1A;(&#x627E;&#x5230;)</p>
<p><img src="../Images/01-&#x7B2C;3&#x5929;-3.gif" alt="&#x7ED3;&#x679C;"></p>
<p>&#x7ED3;&#x679C;2&#xFF1A;(&#x6CA1;&#x6709;&#x627E;&#x5230;)</p>
<p><img src="../Images/01-&#x7B2C;3&#x5929;-4.gif" alt="&#x7ED3;&#x679C;"></p>
<p>&#x8BF4;&#x660E;&#xFF1A;</p>
<blockquote>
<p>in&#x7684;&#x65B9;&#x6CD5;&#x53EA;&#x8981;&#x4F1A;&#x7528;&#x4E86;&#xFF0C;&#x90A3;&#x4E48;not in&#x4E5F;&#x662F;&#x540C;&#x6837;&#x7684;&#x7528;&#x6CD5;&#xFF0C;&#x53EA;&#x4E0D;&#x8FC7;not in&#x5224;&#x65AD;&#x7684;&#x662F;&#x4E0D;&#x5B58;&#x5728;</p>
</blockquote>
<h4 id="index-count">index, count</h4>
<p>index&#x548C;count&#x4E0E;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x7528;&#x6CD5;&#x76F8;&#x540C;</p>
<pre><code class="lang-python"><span class="hljs-prompt">&gt;&gt;&gt; </span>a = [<span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-string">&apos;c&apos;</span>, <span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.index(<span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-number">3</span>) <span class="hljs-comment"># &#x6CE8;&#x610F;&#x662F;&#x5DE6;&#x95ED;&#x53F3;&#x5F00;&#x533A;&#x95F4;</span>
Traceback (most recent call last):
  File <span class="hljs-string">&quot;&lt;stdin&gt;&quot;</span>, line <span class="hljs-number">1</span>, <span class="hljs-keyword">in</span> &lt;module&gt;
ValueError: <span class="hljs-string">&apos;a&apos;</span> <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> list
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.index(<span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-number">1</span>, <span class="hljs-number">4</span>)
<span class="hljs-number">3</span>
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.count(<span class="hljs-string">&apos;b&apos;</span>)
<span class="hljs-number">2</span>
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.count(<span class="hljs-string">&apos;d&apos;</span>)
<span class="hljs-number">0</span>
</code></pre>
<h2 id="&#x5220;&#x9664;&#x5143;&#x7D20;&#x5220;del-pop-remove"><4>&#x5220;&#x9664;&#x5143;&#x7D20;(&quot;&#x5220;&quot;del, pop, remove)</4></h2>
<p>&#x7C7B;&#x6BD4;&#x73B0;&#x5B9E;&#x751F;&#x6D3B;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x67D0;&#x4F4D;&#x540C;&#x5B66;&#x8C03;&#x73ED;&#x4E86;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x5E94;&#x8BE5;&#x628A;&#x8FD9;&#x4E2A;&#x6761;&#x8D70;&#x540E;&#x7684;&#x5B66;&#x751F;&#x7684;&#x59D3;&#x540D;&#x5220;&#x9664;&#x6389;&#xFF1B;&#x5728;&#x5F00;&#x53D1;&#x4E2D;&#x7ECF;&#x5E38;&#x4F1A;&#x7528;&#x5230;&#x5220;&#x9664;&#x8FD9;&#x79CD;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x5217;&#x8868;&#x5143;&#x7D20;&#x7684;&#x5E38;&#x7528;&#x5220;&#x9664;&#x65B9;&#x6CD5;&#x6709;&#xFF1A;</p>
<ul>
<li>del&#xFF1A;&#x6839;&#x636E;&#x4E0B;&#x6807;&#x8FDB;&#x884C;&#x5220;&#x9664;</li>
<li>pop&#xFF1A;&#x5220;&#x9664;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</li>
<li>remove&#xFF1A;&#x6839;&#x636E;&#x5143;&#x7D20;&#x7684;&#x503C;&#x8FDB;&#x884C;&#x5220;&#x9664;</li>
</ul>
<p>demo:(del)</p>
<pre><code class="lang-python">    movieName = [<span class="hljs-string">&apos;&#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;&apos;</span>,<span class="hljs-string">&apos;&#x9A87;&#x5BA2;&#x5E1D;&#x56FD;&apos;</span>,<span class="hljs-string">&apos;&#x7B2C;&#x4E00;&#x6EF4;&#x8840;&apos;</span>,<span class="hljs-string">&apos;&#x6307;&#x73AF;&#x738B;&apos;</span>,<span class="hljs-string">&apos;&#x970D;&#x6BD4;&#x7279;&#x4EBA;&apos;</span>,<span class="hljs-string">&apos;&#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;&apos;</span>]

    print(<span class="hljs-string">&apos;------&#x5220;&#x9664;&#x4E4B;&#x524D;------&apos;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> movieName:
        print(tempName)

    <span class="hljs-keyword">del</span> movieName[<span class="hljs-number">2</span>]

    print(<span class="hljs-string">&apos;------&#x5220;&#x9664;&#x4E4B;&#x540E;------&apos;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> movieName:
        print(tempName)
</code></pre>
<p>&#x7ED3;&#x679C;:</p>
<pre><code>    ------&#x5220;&#x9664;&#x4E4B;&#x524D;------
    &#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;
    &#x9A87;&#x5BA2;&#x5E1D;&#x56FD;
    &#x7B2C;&#x4E00;&#x6EF4;&#x8840;
    &#x6307;&#x73AF;&#x738B;
    &#x970D;&#x6BD4;&#x7279;&#x4EBA;
    &#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;
    ------&#x5220;&#x9664;&#x4E4B;&#x540E;------
    &#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;
    &#x9A87;&#x5BA2;&#x5E1D;&#x56FD;
    &#x6307;&#x73AF;&#x738B;
    &#x970D;&#x6BD4;&#x7279;&#x4EBA;
    &#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;
</code></pre><p>demo:(pop)</p>
<pre><code class="lang-python">    movieName = [<span class="hljs-string">&apos;&#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;&apos;</span>,<span class="hljs-string">&apos;&#x9A87;&#x5BA2;&#x5E1D;&#x56FD;&apos;</span>,<span class="hljs-string">&apos;&#x7B2C;&#x4E00;&#x6EF4;&#x8840;&apos;</span>,<span class="hljs-string">&apos;&#x6307;&#x73AF;&#x738B;&apos;</span>,<span class="hljs-string">&apos;&#x970D;&#x6BD4;&#x7279;&#x4EBA;&apos;</span>,<span class="hljs-string">&apos;&#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;&apos;</span>]

    print(<span class="hljs-string">&apos;------&#x5220;&#x9664;&#x4E4B;&#x524D;------&apos;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> movieName:
        print(tempName)

    movieName.pop()

    print(<span class="hljs-string">&apos;------&#x5220;&#x9664;&#x4E4B;&#x540E;------&apos;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> movieName:
        print(tempName)
</code></pre>
<p>&#x7ED3;&#x679C;:</p>
<pre><code>    ------&#x5220;&#x9664;&#x4E4B;&#x524D;------
    &#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;
    &#x9A87;&#x5BA2;&#x5E1D;&#x56FD;
    &#x7B2C;&#x4E00;&#x6EF4;&#x8840;
    &#x6307;&#x73AF;&#x738B;
    &#x970D;&#x6BD4;&#x7279;&#x4EBA;
    &#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;
    ------&#x5220;&#x9664;&#x4E4B;&#x540E;------
    &#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;
    &#x9A87;&#x5BA2;&#x5E1D;&#x56FD;
    &#x7B2C;&#x4E00;&#x6EF4;&#x8840;
    &#x6307;&#x73AF;&#x738B;
    &#x970D;&#x6BD4;&#x7279;&#x4EBA;
</code></pre><p>demo:(remove)</p>
<pre><code class="lang-python">    movieName = [<span class="hljs-string">&apos;&#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;&apos;</span>,<span class="hljs-string">&apos;&#x9A87;&#x5BA2;&#x5E1D;&#x56FD;&apos;</span>,<span class="hljs-string">&apos;&#x7B2C;&#x4E00;&#x6EF4;&#x8840;&apos;</span>,<span class="hljs-string">&apos;&#x6307;&#x73AF;&#x738B;&apos;</span>,<span class="hljs-string">&apos;&#x970D;&#x6BD4;&#x7279;&#x4EBA;&apos;</span>,<span class="hljs-string">&apos;&#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;&apos;</span>]

    print(<span class="hljs-string">&apos;------&#x5220;&#x9664;&#x4E4B;&#x524D;------&apos;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> movieName:
        print(tempName)

    movieName.remove(<span class="hljs-string">&apos;&#x6307;&#x73AF;&#x738B;&apos;</span>)

    print(<span class="hljs-string">&apos;------&#x5220;&#x9664;&#x4E4B;&#x540E;------&apos;</span>)
    <span class="hljs-keyword">for</span> tempName <span class="hljs-keyword">in</span> movieName:
        print(tempName)
</code></pre>
<p>&#x7ED3;&#x679C;:</p>
<pre><code class="lang-python">    ------&#x5220;&#x9664;&#x4E4B;&#x524D;------
    &#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;
    &#x9A87;&#x5BA2;&#x5E1D;&#x56FD;
    &#x7B2C;&#x4E00;&#x6EF4;&#x8840;
    &#x6307;&#x73AF;&#x738B;
    &#x970D;&#x6BD4;&#x7279;&#x4EBA;
    &#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;
    ------&#x5220;&#x9664;&#x4E4B;&#x540E;------
    &#x52A0;&#x52D2;&#x6BD4;&#x6D77;&#x76D7;
    &#x9A87;&#x5BA2;&#x5E1D;&#x56FD;
    &#x7B2C;&#x4E00;&#x6EF4;&#x8840;
    &#x970D;&#x6BD4;&#x7279;&#x4EBA;
    &#x901F;&#x5EA6;&#x4E0E;&#x6FC0;&#x60C5;
</code></pre>
<h2 id="&#x6392;&#x5E8F;sort-reverse"><5>&#x6392;&#x5E8F;(sort, reverse)</5></h2>
<p>sort&#x65B9;&#x6CD5;&#x662F;&#x5C06;list&#x6309;&#x7279;&#x5B9A;&#x987A;&#x5E8F;&#x91CD;&#x65B0;&#x6392;&#x5217;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x7531;&#x5C0F;&#x5230;&#x5927;&#xFF0C;&#x53C2;&#x6570;reverse=True&#x53EF;&#x6539;&#x4E3A;&#x5012;&#x5E8F;&#xFF0C;&#x7531;&#x5927;&#x5230;&#x5C0F;&#x3002;</p>
<p>reverse&#x65B9;&#x6CD5;&#x662F;&#x5C06;list&#x9006;&#x7F6E;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-prompt">&gt;&gt;&gt; </span>a = [<span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.reverse()
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">1</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.sort()
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
<span class="hljs-prompt">&gt;&gt;&gt; </span>a.sort(reverse=<span class="hljs-keyword">True</span>)
<span class="hljs-prompt">&gt;&gt;&gt; </span>a
[<span class="hljs-number">4</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>]
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../05day/section.6.html" class="navigation navigation-prev " aria-label="Previous page: 列表的循环遍历"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../05day/section.8.html" class="navigation navigation-next " aria-label="Next page: 列表的嵌套"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python基础语言 -->
</html>
